import Vue from 'vue'
import axios from 'axios'

const service = axios.create({
    baseURL: import.meta.env.VITE_BASE_URL,
    timeout: 30 * 1000 // 请求超时时间
})

const err = (error) => {
    const token = localStorage.getItem('token')
    console.log(token)
}

// 请求拦截器
service.interceptors.request.use(config => {
    const token = localStorage.getItem('token')
    if (token) {
        config.headers['Access-Token'] = token
    }
    return config
}, err)

// 响应拦截器
service.interceptors.response.use(response => {
    return response
}, err)

export {
    service as axios
}
